package com.linzm.leetcode.primary.exercises4_20230129;

/**
 * @Author zimingl
 * @Date 2023/2/1 22:45
 * @Description: 缀点成线
 * 给定一个数组 coordinates ，其中 coordinates[i] = [x, y] ， [x, y] 表示横坐标为 x、纵坐标为 y 的点。请你来判断，这些点是否在该坐标系中属于同一条直线上。
 * 输入：coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]
 * 输出：true
 * 2 <= coordinates.length <= 1000
 * coordinates[i].length == 2
 * -10^4 <= coordinates[i][0], coordinates[i][1] <= 10^4
 * coordinates 中不含重复的点
 */
public class Demo6_1232 {
    public static void main(String[] args) {
        Demo6_1232 demo6_1232 = new Demo6_1232();
//        int[][] coordinates = {{1,2},{2,3},{3,4},{4,5},{5,6},{6,7}};
        int[][] coordinates = {{0, -8}, {0, -3}};
//        int[][] coordinates = {{4, 8}, {-2, 8}, {1, 8}, {8, 8}, {-5, 8}, {0, 8}, {7, 8}, {5, 8}};
        boolean checkStraightLine = demo6_1232.checkStraightLine(coordinates);
        System.out.println(checkStraightLine);
    }

    // 00 01 02 , 00 10 20
    private boolean checkStraightLine(int[][] coordinates) {
        int n = coordinates.length - 1;
        for (int i = 1; i < coordinates.length; i++) {
            if ((coordinates[i][0] - coordinates[0][0]) * (coordinates[i][1] - coordinates[n - 1][1])
                    != (coordinates[i][1] - coordinates[0][1]) * (coordinates[i][0] - coordinates[n - 1][0])
            ) {
                return false;
            }
        }
        return true;
    }
}
